import os
from .base import *

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['SECRET_KEY']  # TODO

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['localhost', '.liangyan.fun', '.liangyan.fun.']

# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASE_PASSWORD = os.environ['DATABASE_PASSWORD']  # TODO
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mysite_db',
        'USER': 'huang-jl',
        'PASSWORD': DATABASE_PASSWORD,
        'HOST': 'localhost',
        'PORT': '3306',
    }
}

# CORS settings
CORS_ALLOWED_ORIGINS = [
    'http://localhost:3000',
]

CORS_ALLOW_CREDENTIALS = True

# 邮箱设置
EMAIL_HOST = 'smtp.qq.com'
EMAIL_PORT = 465
EMAIL_USER_SSL = True
EMAIL_HOST_USER = '1046678590@qq.com'
EMAIL_HOST_PASSWORD = os.environ['EMAIL_HOST_PASSWORD']  # TODO
EMAIL_FROM = '1046678590@qq.com'
EMAIL_SUBJECT_PREFIX = '[黄良的网站]'
ADMINS = (
    ('admin', '1046678590@qq.com'),
)

# 日志记录
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
            'style': '{',
        },
    },
    'handlers': {
        'request_warn': {
            'level': 'WARNING',
            'class': 'logging.FileHandler',
            'filename': os.path.join(BASE_DIR, 'request_warn.log'),
            'format': 'verbose',

        },
        'database': {
            'level': 'WARNING',
            'class': 'logging.FileHandler',
            'filename': os.path.join(BASE_DIR, 'database.log'),
            'format': 'verbose',
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
            'format': 'verbose',
        }
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'propagate': True,
        },
        'django.request': {
            'handlers': ['request_warn', 'mail_admins'],
            'level': 'WARNING',
            'propagate': False,
        },
        'django.db.backends': {
            'handlers': ['database'],
            'level': 'WARNING',
            'propagate': False,
        }
    }
}
